package com.ziyia.a273;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.Toolbar;
import android.widget.ViewSwitcher;

public class MainActivity extends AppCompatActivity {


    private TextSwitcher textSwitcher;
    private String[] strs = new String[]{"疯狂Java讲义", "轻量级Java EE企业应用实战", "疯狂Android讲义", "疯狂前端开发讲义"};
    private int curStr;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textSwitcher = findViewById(R.id.textswitch);
        textSwitcher.setFactory(() -> {
            TextView tv = new TextView(MainActivity.this);
            tv.setTextSize(40f);
            tv.setTextColor(Color.MAGENTA);
            return tv;
        });
        // 调用next方法显示下一个字符串
        next(null);
    }

    // 事件处理函数，控制显示下一个字符串
    public void next(View source)
    {
        textSwitcher.setText(strs[curStr++ % strs.length]);  // ①
    }
}